/**
 * Created by wang on 2017/2/28.
 */
$(function(){
	var report = new myReport();
	var myChart;
	var option = {
    	    title: {
    	        text: '签到率',
    	        left: 'left',
    	        textStyle:{fontSize:16,fontWeight:'normal'}
    	    },
    	    tooltip: {
    	        trigger: 'item',
    	        formatter: '{b}</br>{c}'
    	    },
    	    legend: {
    	        left: 'left',
    	        data: ['2的指数', '3的指数']
    	    },
    	    xAxis: {
    	        type: 'category',
    	        name: 'x',
    	        splitLine: {show: false},
    	        data: ""
    	    },
    	    yAxis: {
    	        name: 'y',
    	        type:'value',
    	        axisLabel:{
    	        	rotate:45,
    	        	formatter: function (val) {
                         return (val) * 100 + '%';
                     }
    	        },
    	        splitLine:{
                    show:true,
                    interval:0
                },
    	    },
    	    series: [{
    	    	type: 'line',
    	    	symbol:'circle',
    	        symbolSize:8,
    	        markPoint: {
    	        	symbolSize:35,
                    data: [
                        {type: 'max', name: '最大值'},
                        {type: 'min', name: '最小值'}
                    ]
                },
    	        itemStyle :{
    	              normal:{
    	                  color:"#12b7f5"
    	               }
    	           },
    	        lineStyle:{
    	                normal:{
    	                    color:"#12b7f5",
    	                    width:'2'
    	                }
    	            },
				data:""
				      
    	    }]
    	};
	//弧形百分比图形
	report.daily_gaugechart(_pm);
	//切换按钮初始化与绑定事件
	var span = $($('.daily-month ul li')[0]).children("div").children("span");
	$(span).css("display","block");
	$(span).parent().addClass("daily-active");
	onSwitch();
	//创建echart图标
	CreateEchartZ(_xdataWeek,_ydataWeek);

 function onSwitch(){
	$('.daily-month ul li div').click(function(){
		var _this = $(this);
		$('.daily-month ul li div span').hide();
		$('.daily-month ul li div').removeClass("daily-active");
		_this.children("span").css("display","block");
		_this.addClass("daily-active");
		if(_this.hasClass("week")){
			option.xAxis.data = _xdataWeek;
			var data = [];
		    $.each(_xdataWeek,function(i,r){
		    	var arr = [];
		    	arr.push(r,report.toPoint(_ydataWeek[i]));
		    	data.push(arr);
		    });
			option.series[0].data= data;
			myChart.setOption(option,true);
		}else if(_this.hasClass("month")){
			option.xAxis.data = _xdataMonth;
			var data = [];
		    $.each(_xdataMonth,function(i,r){
		    	var arr = [];
		    	arr.push(r,report.toPoint(_ydataMonth[i]));
		    	data.push(arr);
		    });
			option.series[0].data= data;
			myChart.setOption(option,true);
		}
	});
}
 function CreateEchartZ(x,y){
	    myChart = echarts.init(document.getElementById('echart'));
	    var data = [];
	    $.each(x,function(i,r){
	    	var arr = [];
	    	console.log(report.toPoint(y[i]));
	    	arr.push(r,report.toPoint(y[i]));
	    	data.push(arr);
	    });
	    option.xAxis.data = x;
		option.series[0].data= data;
	    myChart.setOption(option);
 }
});

